import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);
import Layout from "@/views/layout/Layout";
import LayoutLog from "@/views/layout/LayoutLog";
import LayoutError from "@/views/layout/LayoutError";

export const constantRouterMap = [
  {
    path: "/user",
    component: Layout,
    children: [{
      path: "/",
      redirect: "organManagement",
    },
    {
      path: "userManagement",
      component: () => import("@/views/usersManagement/usersList"),
      name: "userManagement",
      meta: {
        title: "用户管理",
        icon: "user",
        noCache: true,
        keepAlive: false
      }
    },
    {
      path: "roleManagement",
      component: () => import("@/views/rolesManagement/rolesList"),
      name: "roleManagement",
      meta: {
        title: "角色管理",
        icon: "role",
        noCache: true,
        keepAlive: false
      }
    },
    {
      path: "menuManagement",
      component: () => import("@/views/menuManagement/menuList"),
      name: "menuManagement",
      meta: {
        title: "菜单管理",
        icon: "role",
        noCache: true,
        keepAlive: false
      }
    },
    {
      path: "organManagement",
      component: () => import("@/views/organManagement/organList"),
      name: "organManagement",
      meta: {
        title: "机构管理",
        icon: "organ",
        noCache: true,
        keepAlive: false
      }
    }]
  },
  {
    path: "/log",
    name: "log",
    component: LayoutLog,
    children: [{
      path: "/",
      redirect: "loginLog"
    },
    {
      path: "loginLog",
      component: () => import("@/views/logs/loginLog"),
      name: "loginLog",
      meta: {
        title: "登录日志",
        icon: "businessOperationsLog",
        noCache: true,
        keepAlive: false
      }
    }, {
      path: "operationsLog",
      component: () => import("@/views/logs/operationsLog"),
      name: "operationsLog",
      meta: {
        title: "操作日志",
        icon: "operationsLog",
        noCache: true,
        keepAlive: false
      }
    },
    {
      path: "interfaceServiceLog",
      component: () => import("@/views/logs/interfaceServiceLog"),
      name: "interfaceServiceLog",
      meta: {
        title: "接口服务日志",
        icon: "interfaceServiceLog",
        noCache: true,
        keepAlive: false
      }
    }]
  },
  {
    path: "/",
    component: LayoutError,
    children: [{
      path: "/",
      redirect: "error",
    },
    {
      path: "error",
      component: () => import("@/views/layout/components/error"),
      name: "error",
      meta: {
        title: "无权访问",
        icon: "error",
        noCache: true,
        keepAlive: false
      }
    }]
  },
];

export default new Router({
  mode: "history", // require service support
  base: process.env.BASE_URL,
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
});
